<?php
session_start();
if(!isset($_SESSION['uid']))
 	{?>
		<script type="text/javascript">
			window.location="error.php";
		</script>
	<?php 
 	}else 		
 		{
			require_once 'dataBaseConnectivityFile.php';
			$time_stamp=date('d_M_Y_H.i.s');
			$fileName = $_FILES["image"]["name"];
			$fileTmpLoc = $_FILES["image"]["tmp_name"];
			$pathAndName = "CarImages/".$time_stamp."_".$fileName;
			$moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
			$get_stock_id=$_REQUEST['stock_id'];
		
			if($moveResult==true)
			{
				$sql_query="INSERT INTO vehicle_image (STOCK_ID,PATH,CREATE_DATE) VALUES('".$get_stock_id."', '".$pathAndName."', NOW())";
				if(!mysql_query($sql_query,$con))
				{
					die ("ERROR ".mysql_error());
				}else{
					?>
					<script type="text/javascript">
						alert("Image Added");
						window.location="viewDetails.php?stock_id="+<?php echo $get_stock_id?>;
					</script>
					<?php 
				}
			}
 	}
 	?>